<?php
// Only display Categories that have products
/*
    $strSQL = "SELECT DISTINCT
					  tblCategory.CategoryID
					, tblCategory.CategoryName
				FROM tblCategory, tblProducts
				WHERE tblCategory.CategoryID = tblProducts.CategoryID
				ORDER BY CategoryName;";
				//echo $strSQL;
*/

    $strMenuSQL = "SELECT tblCategory.ID				CategoryID
						, tblCategory.Category			CategoryName
						, tblSubCategory.ID				SubCategoryID
						, tblSubCategory.SubCategory
						, tblProduct.ID
						, tblProduct.Product
					FROM tblProduct 
							LEFT JOIN tblSubCategoryAndProduct ON tblProduct.ID = tblSubCategoryAndProduct.Product 
							LEFT JOIN tblSubCategory ON tblSubCategoryAndProduct.SubCategory = tblSubCategory.ID 
							LEFT JOIN tblCategory ON tblSubCategory.Category = tblCategory.ID
					WHERE tblProduct.Product Is Not Null AND tblProduct.Discontinued=0 AND tblCategory.ID Is Not Null
				";
				//echo $strSQL;
	
	$strJoin = " AND ";

    if ($intMenuCategoryID){
        $strMenuSQL .= $strJoin."tblCategory.ID = '$intMenuCategoryID'";
        $strJoin = " AND ";
		unset($intMenuCategoryID);
    }

	$strMenuSQL .= " ORDER BY CategoryName, SubCategory, tblProduct.Product";
	$objSideMenu = new MySqlResults($strMenuSQL);

?>
